package com.pt25.service.sys.interfaces.facade.inner;


import com.pt25.base.model.security.aspect.PermissionCheck;
import com.pt25.base.res.ResBody;
import com.pt25.service.sys.application.AdminApp;
import com.pt25.service.sys.interfaces.assembler.AdminAssembler;
import com.pt25.service.sys.interfaces.vo.admin.permission.AdminPermissionAddVo;
import com.pt25.service.sys.interfaces.vo.admin.permission.AdminPermissionUpdateVo;
import com.pt25.service.sys.interfaces.vo.admin.role.AdminRoleAddVo;
import com.pt25.service.sys.interfaces.vo.admin.role.AdminRolePageVo;
import com.pt25.service.sys.interfaces.vo.admin.role.AdminRoleUpdateVo;
import com.pt25.service.sys.interfaces.vo.admin.user.AdminUserAddVo;
import com.pt25.service.sys.interfaces.vo.admin.user.AdminUserPageVo;
import com.pt25.service.sys.interfaces.vo.admin.user.AdminUserUpdateVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@Tag(name = "admin inner api")
@RestController
@RequestMapping("/inner-api/sys")
public class AdminInnerController {
    private final static String ADD_ADMIN_USER = "/admin-user";
    private final static String DEL_ADMIN_USER = "/admin-user/{id}";
    private final static String UPDATE_ADMIN_USER = "/admin-user";
    private final static String GET_ADMIN_USER = "/admin-user/{id}";
    private final static String PAGE_ADMIN_USER = "/admin-user/page";
    private final static String ADD_ADMIN_ROLE = "/admin-role";
    private final static String DEL_ADMIN_ROLE = "/admin-role/{id}";
    private final static String UPDATE_ADMIN_ROLE = "/admin-role";
    private final static String GET_ADMIN_ROLE = "/admin-role/{id}";
    private final static String PAGE_ADMIN_ROLE = "/admin-role/page";
    private final static String ADD_ADMIN_PERMISSION = "/admin-permission";
    private final static String DEL_ADMIN_PERMISSION = "/admin-permission/{id}";
    private final static String UPDATE_ADMIN_PERMISSION = "/admin-permission";
    private final static String GET_ADMIN_PERMISSION = "/admin-permission/{id}";
    private final static String TREE_ADMIN_PERMISSION = "/admin-permission/tree";


    @Resource
    private AdminApp adminApp;

    @PermissionCheck("sys:admin-user:add")
    @PostMapping(ADD_ADMIN_USER)
    public ResBody addAdminUser(@RequestBody AdminUserAddVo adminUserAddVO) {
        adminApp.addAdminUser(AdminAssembler.adminUserAddVO2AdminUser(adminUserAddVO));
        return ResBody.builder().build().ok();
    }

    @PermissionCheck("sys:admin-user:del")
    @DeleteMapping(DEL_ADMIN_USER)
    public ResBody delAdminUser(@PathVariable("id") Long id) {
        adminApp.delAdminUser(id);
        return ResBody.builder().build().ok();
    }

    @PermissionCheck("sys:admin-user:update")
    @PutMapping(UPDATE_ADMIN_USER)
    public ResBody updateAdminUser(@RequestBody AdminUserUpdateVo adminUserUpdateVO) {
        adminApp.updateAdminUser(AdminAssembler.adminUserUpdateVO2AdminUser(adminUserUpdateVO));
        return ResBody.builder().build().ok();
    }

    @PermissionCheck("sys:admin-user:get")
    @GetMapping(GET_ADMIN_USER)
    public ResBody getAdminUser(@PathVariable("id") Long id) {
        return ResBody.builder().build().ok(adminApp.getAdminUser(id));
    }

    @PermissionCheck("sys:admin-user:page")
    @GetMapping(PAGE_ADMIN_USER)
    public ResBody pageAdminUser(@RequestBody AdminUserPageVo adminUserPageVO) {
        return ResBody.builder().build().ok(adminApp.pageAdminUser(AdminAssembler.adminUserPageVOToAdminUser(adminUserPageVO)));
    }

    @PermissionCheck("sys:admin-role:add")
    @PostMapping(ADD_ADMIN_ROLE)
    public ResBody addAdminRole(@RequestBody AdminRoleAddVo adminRoleAddVO) {
        adminApp.addAdminRole(AdminAssembler.adminRoleAddVO2AdminRole(adminRoleAddVO));
        return ResBody.builder().build().ok();
    }

    @PermissionCheck("sys:admin-role:del")
    @DeleteMapping(DEL_ADMIN_ROLE)
    public ResBody delAdminRole(@PathVariable("id") Long id) {
        adminApp.delAdminRole(id);
        return ResBody.builder().build().ok();
    }

    @PermissionCheck("sys:admin-role:update")
    @PutMapping(UPDATE_ADMIN_ROLE)
    public ResBody updateAdminRole(@RequestBody AdminRoleUpdateVo adminRoleUpdateVO) {
        adminApp.updateAdminRole(AdminAssembler.adminRoleUpdateVO2AdminRole(adminRoleUpdateVO));
        return ResBody.builder().build().ok();
    }

    @PermissionCheck("sys:admin-role:get")
    @GetMapping(GET_ADMIN_ROLE)
    public ResBody getAdminRole(@PathVariable("id") Long id) {
        return ResBody.builder().build().ok(adminApp.getAdminRole(id));
    }

    @PermissionCheck("sys:admin-role:page")
    @PostMapping(PAGE_ADMIN_ROLE)
    public ResBody pageAdminRole(@RequestBody AdminRolePageVo adminRolePageVO) {
        return ResBody.builder().build().ok(adminApp.pageAdminRole(AdminAssembler.adminRolePageVOToAdminRole(adminRolePageVO)));
    }

    @PermissionCheck("sys:admin-permission:add")
    @PostMapping(ADD_ADMIN_PERMISSION)
    public ResBody addAdminPermission(@RequestBody AdminPermissionAddVo adminPermissionAddVO) {
        adminApp.addAdminPermission(AdminAssembler.adminPermissionAddVO2AdminPermission(adminPermissionAddVO));
        return ResBody.builder().build().ok();
    }

    @PermissionCheck("sys:admin-permission:del")
    @DeleteMapping(DEL_ADMIN_PERMISSION)
    public ResBody delAdminPermission(@PathVariable("id") Long id) {
        adminApp.delAdminPermission(id);
        return ResBody.builder().build().ok();
    }

    @PermissionCheck("sys:admin-permission:update")
    @PutMapping(UPDATE_ADMIN_PERMISSION)
    public ResBody updateAdminPermission(@RequestBody AdminPermissionUpdateVo adminPermissionUpdateVO) {
        adminApp.updateAdminPermission(AdminAssembler.adminPermissionUpdateVO2AdminPermission(adminPermissionUpdateVO));
        return ResBody.builder().build().ok();
    }

    @PermissionCheck("sys:admin-permission:get")
    @GetMapping(GET_ADMIN_PERMISSION)
    public ResBody getAdminPermission(@PathVariable("id") Long id) {
        return ResBody.builder().build().ok(adminApp.getAdminPermission(id));
    }

    @PermissionCheck("sys:admin-permission:tree")
    @GetMapping(TREE_ADMIN_PERMISSION)
    public ResBody treeAdminPermission() {
        return ResBody.builder().build().ok(adminApp.treeAdminPermission());
    }

}
